// Problem: 
// Contest: 
// URL: 
// Memory Limit: 
// Time Limit: 
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
int n,ans=0;
vector<int> v,dp;
vector<vector<unordered_map<int,int>>> tmp;
unordered_map<int,int> s;
void dfs(int x)
{
	bool f=0;
	for(int i=0;i<(int)tmp.size();i++)
	{
		if(s==tmp[x][i])return;
	}
	tmp[x].push_back(s);
	if(x+v[x]<=n)s[v[x+v[x]]]=1,dfs(x+v[x]),f=1;
	if(x*2<=n)s[v[x*2]]=1,dfs(x*2),f=1;
	if(!f)ans=max(ans,(int)s.size());
}
void solve()
{
	
	cin>>n;
	v=dp=vector<int> (n+1);
	tmp=vector<vector<unordered_map<int,int>>>(n+1);
	for(int i=1;i<=n;i++)
	{
		cin>>v[i];
	}
	for(int i=1;i<=n;i++)
	{
		s.clear();
		s[v[i]]=1;
		dfs(i);
	}
	cout<<ans<<endl;
}
signed main()
{
	int T=1;
//	cin>>T;
	while(T--)
	{
		solve();
	}
	return 0;
}
